package com.cz.ssyx.sys.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.cz.ssyx.common.exception.MyException;
import com.cz.ssyx.common.result.ResultCodeEnum;
import com.cz.ssyx.model.sys.RegionWare;
import com.cz.ssyx.sys.mapper.RegionWareMapper;
import com.cz.ssyx.sys.service.RegionWareService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.swagger.models.auth.In;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 城市仓库关联表 服务实现类
 * </p>
 *
 * @author Joker
 * @since 2024-04-17
 */
@Service
public class RegionWareServiceImpl extends ServiceImpl<RegionWareMapper, RegionWare> implements RegionWareService {

    //新增开通区域
    @Override
    public void saveRegionWare(RegionWare regionWare) {
        //先判断是否以及开通此区域
        LambdaQueryWrapper<RegionWare> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(RegionWare::getRegionId, regionWare.getRegionId());
        int count = this.count(queryWrapper);
        if (count > 0) {
            throw new MyException(ResultCodeEnum.REGION_OPEN);
        }
        this.save(regionWare);
    }
}
